# This is a sample Python script.

# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.

import random
import platform
import datetime
import re
import os
import shutil
from flask import Flask
import sqlite3

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    """

    :param name:
    :return:
    """
    x = 5
    y = 6
    print(f'Hi, {name} ' + str(x+y) + str(random.randint(1, 100)))  # Press ⌘F8 to toggle the breakpoint.
    return  x + y

# class Person:
#   def __init__(self, fname, lname):
#     self.firstname = fname
#     self.lastname = lname
#
#   def show(self):
#     print(f"I am {self.firstname}, age is {self.lastname}")


app = Flask(__name__)
cnn = sqlite3.connect('demo.db')

# sql='create table user ( userid integer primary key autoincrement, \
#                          username varchar(20), userpwd varchar(20))'
# cnn.execute(sql)
# cnn.commit()
# cnn.close()

def db_action(sql, actionType=0):
    try:
        res = cnn.execute(sql)
        if actionType == 1:
            return res
        else:
            return True
    except ValueError as e:
        print(e)

# userlist = "(null,'程咬金12322','1234'),(null,'caojianhua','cao1234'),(null,'lina','lina123'),(null,'dar','dar23'),(null,'caojh','cao123')"
# sql = 'insert into user values ' + userlist
# if db_action(sql, 0) == True:
#     print('插入记录成功')
# cnn.commit()
# cnn.close()

def db_queryAllUser():
    sql = 'select * from user'
    userlist = db_action(sql, 1)
    for user in userlist:
        print(f'==== u: {user}')
    return userlist

@app.route('/')
def index():

    return '{\"code\": 0, \"msg\": \"ccccc\"}'

# Press the green button in the gutter to run the script.
if __name__ == '__main__':

    # folder_path = "/Users/mbc/Downloads/dooo/otherAsset"
    #
    # for filename in os.listdir(folder_path):
    #     print(f"==== filename {filename}")
    #     newname = filename.replace(".png", "@3x.png")
    #     os.renames(os.path.join(folder_path, filename), os.path.join(folder_path, newname))

    app.run(port=2020, host="127.0.0.1", debug=True)

    base_folder = "/Users/mbc/Downloads/dooo/baseAsset"
    other_folder = "/Users/mbc/Downloads/dooo/otherAsset"
    folder_path = "/Users/mbc/Downloads/dooo/mine"

    for dirname in os.listdir(folder_path):
        dirPath = os.path.join(folder_path, dirname)
        if os.path.isdir(dirPath):
            for filename in os.listdir(dirPath):
                if filename.endswith("@3x.png"):
                    newname = dirname.replace(".imageset", "@3x.png")
                    os.renames(os.path.join(dirPath, filename), os.path.join(dirPath, newname))
                    size = os.path.getsize(os.path.join(dirPath, newname))
                    print(f"===== ffffff: {filename} == {newname} === {size}")
                    if size < 5500:
                        shutil.move(os.path.join(dirPath, newname), os.path.join(base_folder, newname))
                    else:
                        shutil.move(os.path.join(dirPath, newname), os.path.join(other_folder, newname))
                    break

    help(print_hi)
    age = 18
    waite = 175.5623

    age = int(input("Please input your age: "))

    print('my age is %d' % age)
    print('my waite is %.1f' % waite)


    a = """hahaccc
this is a apple
    this is new line
    this is last line
    abcdefg
    """
    b = ["apple1", "apple2", "apple3", "apple4", "apple5", "apple6"]
    c = "hello world"
    name = "Python3"
    # print_hi("PyCharm " + name)
    print(a[2:5])
    print(b[2:5])
    print(c[2:5])
    print(b[-3:-1])
    print(bool(-1))
    print(f"test bool-str {bool('')}")
    print(bool(()))
    print(5 | 1)
    b[1] = "apple10"
    b.append("apple100")
    e = ["color1", "color2", "color3", "color4"]
    b.sort()
    for x in b:
        print(x)

    print(len(b))
    f = (1)
    print(type(f))
    h = 300
    i = 500
    print('A') if h > i else print('B') if h == i else print('C')

    for x in range(3, 50, 6):
        print(x)
    else:
        print("for loop exit")

    def testOne(x, y = 100):
        print(f"result is: {x+y}")

    testOne(6)

    def reve(k):
        if k > 0:
            return k + reve(k-1)
        else:
            return 0

    print(reve(500))

    def funcModel(n):
        return lambda a: a * n

    funcOne = funcModel(3)
    funcTwo = funcModel(5)

    print(funcOne(6))
    print(funcTwo(6))


    class Person:
        def __init__(self, zname, age):
            self.fname = zname
            self.fage = age

        def show(self):
            print(f"I am {self.fname}, age is {self.fage}")


    class Student(Person):
        def __init__(self, name, age):
            super().__init__(name, age)
            self.money = "$99999999"

        def show(self):
            super().show()
            print(f"child print: {self.money}")

    s1 = Student("Wei", 16)
    s1.show()

    t = iter(b)
    for i in range(len(b)):
        print(next(t))

    print(f"date is: {datetime.datetime.now().strftime('%a')}")

    str1 = "hello world, hello python"
    x1 = re.search('^he.*on$', str1)
    x2 = re.findall('h\w+o', str1)
    print(f"xxxx: {x2}")

    name1 = input()
    print(f'hello {name1}')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
